<template>
	<view class="main-box ">

		<!-- 	<u-popup v-model="shows" mode="center" v-if="flag==2">
			<view class="" style="width: 100%;text-align: center;">

				<image mode="widthFix" src="../../static/err1.png" @click="errs" class="img"></image>
				<image src="../../static/queren.png" mode="widthFix" class="img" style="margin-top: 20rpx;"
					@click="errs"></image>
			</view>
		</u-popup> -->
	<!-- 	<u-popup v-model="showsq" mode="center">
			<view class="" style="width: 100%;text-align: center;">

				<image mode="widthFix" src="../../static/shouquan.png" style="width: 90%;position: relative;"></image>
				<image mode="widthFix" src="../../static/shouquanbt.png" class="img"
					style="position: absolute;top: 320rpx;left:70rpx;"></image>
				<button type="default" open-type="getAuthorize" @getAuthorize="onGetAuthorize" scope='phoneNumber'
					style="position: absolute;top: 320rpx;left:70rpx;width: 80%;opacity: 0;">授权</button>

			</view>
		</u-popup> -->
		<u-popup v-model="showqd" mode="center">
			<view class="" style="width: 100%;text-align: center;">

				<image mode="widthFix" src="../../static/daozhang.png" style="width: 90%;position: relative;"></image>



			</view>
			<image mode="widthFix" src="../../static/daozhangqd.png"
				style="position: absolute;top: 320rpx;left:172rpx;width: 420rpx;" @click="kabao"></image>
		</u-popup>
		<!-- <view class="" style="background-color: #347af0;height: 100vh;" v-if="flag==1">
			<image src="../../static/sucesss.png" mode="widthFix" style="width: 100%;"></image>
		</view>
		<view class="" style="background-color: #e1f3ff;height: 100vh;" v-if="flag==3">
			<image src="https://web.78keji.cn/images/yundian/背景@3x.png" mode="widthFix" style="width: 100%;"></image>
			<view class="" style="padding: 24rpx;">
				<view class="bns">
					<image src="https://web.78keji.cn/images/yundian/biaoti1.png" mode="widthFix" style="width: 100%;">
					</image>
					<image src="https://web.78keji.cn/images/yundian/1.gif" mode="widthFix"
						style="width: 100%;margin-top: 20rpx;"></image>
					<image src="https://web.78keji.cn/images/yundian/btn2@3x.png" mode="widthFix"
						style="width: 100%;margin-top:30rpx;" @click="kabao"></image>

				</view>
				<view class="bns" style="margin-top: 40rpx;">
					<image src="https://web.78keji.cn/images/yundian/biaoti2.png" mode="widthFix" style="width: 100%;">
					</image>
					<image src="https://web.78keji.cn/images/yundian/2.gif" mode="widthFix"
						style="width: 100%;margin-top: 20rpx;"></image>
					<image src="https://web.78keji.cn/images/yundian/btn.png" mode="widthFix"
						style="width: 100%;margin-top:30rpx;" @click="chongzhi"></image>

				</view>
				<view class="" style="height: 100rpx;">

				</view>
			</view>
		</view> -->


		<!-- style="position: fixed;bottom: 0;height: 500rpx;overflow-y: auto;" -->
		<view class="">
			<ads onSuccess="onSuccess" onAdError='onAdError' onClose="onClose" onInsuranceStatus='onInsuranceStatus'></ads>
		</view>

	</view>
</template>
<script>
	import {
		getdata,
		addLog,
		getUrl,
		addNum,
		statusx,
		getcode,
		logs,
		openSignDecrypt,
		bindMobile
		
	} from '../../api/index.js'
	export default {
		data() {
			return {
				showsq: false,
				interstitialAd: null,
				flag: 0,
				shows: true,
				a: "",
				times: '0',
				type: "",
				spaceCode: "",
				showqd: false,
				mobile: ''
			}
		},
		components: {

		},

		methods: {
			onGetAuthorize() {
				uni.showLoading({
					title: "授权中",
					mask: true
				})
				my.getPhoneNumber({
					success: (res) => {
						let encryptedData = res.response;
						console.log(encryptedData)
						openSignDecrypt({
							encryptedData: JSON.parse(encryptedData).response,
							xcx: 3
						}).then((resx) => {
							console.log(resx)
							uni.setStorageSync('mobile', resx.data.mobile)
							uni.setStorageSync('openid', resx.data.openid)
							this.mobile = resx.data.mobile
							this.openid = resx.data.openid
							uni.hideLoading()
							my.getAuthCode({
								scopes: 'auth_base',
								success: (res) => {
									console.log(res)
									my.request({
										url: 'https://www.sx2b2c.com/api/rf/getAliUserid', // 请求的 URL
										method: 'POST', // POST 方法
										data: {
											code: res.authCode,
											pro_id: 2014
										},
										header: {
											'Content-Type': 'application/x-www-form-urlencoded' // 设置请求头
										},
										success: (result) => {
											this.showqd = true
											this.showsq = false
											bindMobile({
												mobile: this.mobile,
												user_id: result.data
													.data.user_id
											}).then((res) => {
												console.log(res)
											})
											my.setStorageSync({
												key: 'user',
												data: result.data.data
													.user_id
											})

										},
										fail: function() {

										}
									})

								},
							});

						})

					},
					fail: (res) => {
						console.log(res);
						uni.hideLoading()
						console.log('getPhoneNumber_fail');
					},
				});


			},
			// #ifdef MP-ALIPAY
			onInsuranceStatus() {
				uni.showLoading({
					title: '获取结果中'
				});
				console.log('投保成功88888888')
				setTimeout(()=> {

					getdata({
						orderNo: my.getStorageSync({
							key: 'orderNo'
						}).data
					}).then((res) => {
						uni.hideLoading()
						this.showqd = true
					}).catch((err) => {
						console.log('失败')
						uni.hideLoading()
						
						
					})

				}, 5000);


			},
			onSuccess() {

				logs({
					a: my.getStorageSync({
						key: 'a'
					}).data,
					eventType: 3,
					xcx: 4,
					spaceCode:'50_2024030725000084382',
					deviceid: my.getStorageSync({
						key: 'deviceid'
					}).data
				}).then((res) => {
					console.log(res)
				})

			},
			onClose() {
				// this.flagg=true
				// this.onInsuranceStatus()
				console.log("广告关闭")
				my.exitMiniProgram();
			},
			chongzhi() {
				let link = "https://render.alipay.com/p/s/i/?scheme=" + encodeURIComponent(
					"alipayqr://platformapi/startapp?saId=10000003")

				my.ap.navigateToAlipayPage({
					path: link
				})
			},

			kabao() {
				uni.reLaunch({
					url:'/pages/ljjlq/ljjlq'
				})


			},
			onAdError(){
		// console.log('拉去失败跳转全屏')	
		// uni.navigateTo({
		// 	url:'/pages/nfull/nfull'
		// })
			},
		
			// #endif
		},
		onLoad(option) {
			this.$scope.onSuccess = this.onSuccess.bind(this)
				this.$scope.onAdError = this.onAdError.bind(this)
			this.$scope.onInsuranceStatus = this.onInsuranceStatus.bind(this)

			this.$scope.onClose = this.onClose.bind(this)
			let link = "https://render.alipay.com/p/s/i/?scheme=" + encodeURIComponent(
				"alipayqr://platformapi/startapp?saId=88888888")
			console.log(link)
			//其他小程序调过来
			uni.setStorageSync('times', 0)
			// #ifdef MP-ALIPAY

			if (option.mobile) {
				my.setStorageSync({
					key: 'mobile',
					data: option.mobile
				})

			}
			if (option.a) {
				my.setStorageSync({
					key: 'a',
					data: option.a
				})

			}

			if (option.param) {
				my.setStorageSync({
					key: 'param',
					data: option.param
				})

			}



			// #endif

		},

		onUnload() {

		},

		onShow() {
			// #ifdef MP-ALIPAY
			// uni.setStorageSync('a', option.a)


			getcode({
				a: my.getStorageSync({
					key: 'a'
				}).data,
				xcx: 4
			}).then((res) => {
				this.type = res.data.type
				this.spaceCode = res.data.spaceCode
				logs({
					a: my.getStorageSync({
						key: 'a'
					}).data,
					eventType: 4,
					xcx: 4,
					spaceCode:'50_2024030725000084382',
					pages: "pages/ncheck/ncheck",
					orderNo: my.getStorageSync({
						key: 'orderNo'
					}).data,
					deviceid: my.getStorageSync({
						key: 'deviceid'
					}).data
				}).then((res) => {

				})
			
			})




			// #endif

		},


		watch: {


		},
		computed: {

		}
	}
</script>

<style lang='scss'>
	.main-box {
		min-height: 100%;
		position: relative;
		/* 	background-color: red; */



	}

	.img {
		height: 80%;
		width: 80%;
	}

	.box {
		height: 100%;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.bns {
		width: 100%;
		background: #FFFFFF;
		box-shadow: 0rpx 2rpx 5rpx 0rpx rgba(16, 104, 195, 0.3);
		border-radius: 25rpx;
		padding: 50rpx 50rpx 0 50rpx;
	}
</style>